<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link href="/erp/assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/font/css/font-awesome.min.css"/>
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link href="/erp/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/erp/assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="/erp/js/jquery-1.9.1.min.js"></script>
    <script src="/erp/assets/js/bootstrap.min.js"></script>
    <script src="/erp/assets/js/typeahead-bs2.min.js"></script>
    <script src="/erp/assets/js/jquery.dataTables.min.js"></script>
    <script src="/erp/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="/erp/assets/layer/layer.js" type="text/javascript"></script>
    <script src="/erp/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="/erp/js/displayPart.js" type="text/javascript"></script>
</head>
<body>

<div class="add_menber" id="add_menber">
    <form>
        <ul class=" page-content">
            <div class="Operate_cont clearfix">
                <label class="form-label">入库单号：</label>
                <div class="formControls ">
                    <input type="text" class="input-text" value="" id="ioNo" name="ioNo">
                    <label class="form-label" id="tsioNo"></label>
                </div>
            </div>
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span>入库类型：</label>

                <div class="formControls ">
                    <select class="rklx" name="ioType" style="margin-left:10px;">
                        <option value="0">请选择入库类型</option>
                        <option>采购订单入库</option>
                        <option>生产入库</option>
                    </select>
                </div>
            </div>
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span>批次：</label>
                <div class="formControls ">
                    <input type="text" class="input-text" value="" placeholder="" id="batch" name="batch">
                    <label class="form-label" id="tsbatch"></label>
                </div>
            </div>
            <div class="Operate_cont clearfix">
                <table class="table table-striped table-bordered table-hover" id="sample-table2">
                    <thead>
                    <tr>
                        <th width="100">商品ID</th>
                        <th width="100">订单ID</th>
                        <th width="100">商品名称</th>
                        <th width="100">仓库名称</th>
                        <th width="100">货区名称</th>
                        <th width="100">货架编号</th>
                        <th width="100">货位编号</th>
                        <th width="100">状态</th>
                        <th width="100">操作</th>
                    </tr>
                    </thead>
                </table>


            </div>
        </ul>
    </form>
    <input type="hidden" id="hidden">
</div>

<script>

//<!--判断入库单号不为空-->
    $("#ioNo").blur(function () {
        var iono=$("#ioNo").val();
        if (iono==""||iono==null){
            $("#tsioNo").empty().append("<font color=\"#FF0000\">入库单号不能为空</font>");
            // $("#tsioNo").text("入库单号不能为空");
            $("#ioNo").focus();
        }else {
            $("#tsioNo").empty();
        }
    });

<!--判断批次号不为空-->
    $("#batch").blur(function () {
        var batch=$("#batch").val();
        if (batch==""||batch==null){
            $("#tsbatch").empty().append("<font color=\"#FF0000\">批次号不能为空</font>");
            // $("#tsioNo").text("入库单号不能为空");
            $("#batch").focus();
        }else {
            $("#tsbatch").empty();
        }
    });


    //加载商品信息
    $('.rklx').on('change', function () {
        //获取入库类型
        var a = $(this).val();
        if(a=="请选择入库类型"||a=="0"||a==""){
            return;
        }
           console.log(a);
            var p;
            $.ajax({
                url: '/io-warehouse/warehouseAll',
                type: 'post',
                contentType: 'application/json',
                dataType: 'json',
                success: function (res) {
                    p = res;
                }
            })

            var oTable1 = $('#sample-table2').DataTable({
                "serverSide": false,     // true表示使用后台分页
                "destroy": true,
                ajax: {
                    "url": "/io-warehouse/storageAll",  // 异步传输的后端接口url
                    "type": "POST",  // 请求方式
                    "dataSrc": '',
                    "data": {
                        "type": a
                    },
                },
                "bStateSave": true,//状态保存
                'autoWidth': true,
                "columns": [
                    {
                        "data": "pid"
                    },
                    {
                        "data": "oid"
                    },
                    {"data": "pname"},
                    {
                        "data": "pid",
                        "createdCell": function (td, cellData, rowData, row, col) {
                            //加载仓库
                            var select = $('<select class="ck"></select>');
                            $(select).empty();
                            $(select).append("<option value='0'>请选择仓库</option>");
                            console.log('xxxx');
                            for (var c in p) {
                                $(select).append("<option value='" + p[c].id + "'>" + p[c].warehouseName + "</option>")
                            }
                            $(td).empty().append(select);
                        }
                    },

                    {
                        "data":"pid",
                        "createdCell": function (td, cellData, rowData, row, col) {
                            var select = $('<select class="hq"></select>');
                            $(select).append("<option value='0'>请选择货区</option>");
                            $(td).empty().append(select);
                        }
                    },

                    {
                        "data":"pid",
                        "createdCell": function (td, cellData, rowData, row, col) {
                            var select = $('<select class="hj"></select>');
                            $(select).append("<option value='0'>请选择货架</option>");
                            $(td).empty().append(select);
                        }
                    },

                    {
                        "data":"pid",
                        "createdCell": function (td, cellData, rowData, row, col) {
                            var select = $('<select class="hw"></select>');
                            $(select).append("<option value='0'>请选择货位</option>");
                            $(td).empty().append(select);
                        }
                    },

                    {
                        "data":"pid",
                        "createdCell": function (td, cellData, rowData, row, col) {
                            $(td).empty().append('<span class="td-status">未确定</span>')
                        }
                    },

                    {
                        "data":"pid",
                        "createdCell": function (td, cellData, rowData, row, col) {
                            console.log(row);
                            $(td).empty().append('<a onClick="member_stop(this)" href="javascript:;" title="停用" class="btn btn-xs btn-success"><i class="icon-ok bigger-120"></i></a>');
                        }
                    }
                ]
            });

            return;
    });

        //加载货区
        $('table').on('change', '.ck', function () {
            console.log("123");
            var a = $(this).val();
            var hq = $(this).parent().parent().find(".hq");
            $.get("/io-warehouse/areaAll?warehouseName=" + a, function (res) {
                $(hq).empty();
                $(hq).append("<option value='0'>请选择货区</option>")
                for (var q in res) {
                    $(hq).append("<option value='" + res[q].id + "'>" + res[q].name + "</option>")
                }
            });
    })

    //加载货架
    $('table').on('change','.hq', function () {
        var w = $(this).parent().parent().find(".ck").val();
        var a = $(this).val();
        var hj = $(this).parent().parent().find(".hj");
        $.post("/io-warehouse/shelfAll", {
            warehouseName: w,
            areaName: a
        }, function (res) {
            $(hj).empty()
            $(hj).append("<option value='0'>请选择货架</option>")
            for (var q in res) {
                $(hj).append("<option value='" + res[q].id + "'>" + res[q].shelfNo + "</option>")
            }
        })

    })

    //加载货位
    $('table').on('change','.hj', function () {

        var w = $(this).parent().parent().find(".ck").val();
        var a = $(this).parent().parent().find(".hq").val();
        var s = $(this).parent().parent().find(".hj").val();
        var hw = $(this).parent().parent().find(".hw");
        $.post("/io-warehouse/spaceAll", {
            warehouseName: w,
            areaName: a,
            shelfNo: s
        }, function (res) {
            $(hw).empty();
            $(hw).append("<option value='0'>请选择货位</option>")
            for (var q in res) {
                $(hw).append("<option>" + res[q].spaceNo + "</option>")
            }
        })
    });

    /*入库按钮*/
    function member_stop(obj){
        if($("#ioNo").val()==""||$("#ioNo").val()==null||$("#batch").val()==""||$("#batch").val()==null){
            layer.msg('有选项为空,请根据提示把信息填完整',{icon: 5,time:3000});
            return;
        }
        var tds = $(obj).parent().parent().find("td");
        var row = {
            pid : $(tds[0]).text(),
            oid :$(tds[1]).text(),
            name: $(tds[2]).text(),
            ck: $(tds[3]).children().val(),
            hq: $(tds[4]).children().val(),
            hj: $(tds[5]).children().val(),
            hw: $(tds[6]).children().val()
        };

      var data = $.param(row) + "&" + $('form').serialize();
        console.log(data);

        if (row.ck!='0'&&row.hq!='0'&&row.hj!='0'&&row.hw!='0'){
            $.post("/io-warehouse/storageAdd",data,function (res) {
                if(res.flag){
                    layer.msg(res.message,{icon: 6,time:1000});
                    $(obj).parent().prev().find(".td-status").html('<span class="label label-success radius">已入库</span>');
                    $(obj).remove();
                    console.log("xxx");
                    $("#hidden",window.parent.document).click();
                }else {
                    layer.msg(res.message,{icon: 5,time:1000});
                }
            })
        }else {
            layer.msg('请把入库的仓库具体信息填完整',{icon: 5,time:3000});
        }


    }



</script>
</body>
</html>